//
//  YDOAAnnounceVC.swift
//  YDOAProduct
//
//  Created by YDWY on 2017/5/27.
//  Copyright © 2017年 Allen. All rights reserved.
//

import UIKit
import Toaster
class YDOAAnnounceVC: UIViewController {

    @IBOutlet weak var titleTF: UITextField!
    @IBOutlet weak var contentView: UITextView!
    
   
    
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
       // self.navigationController?.navigationBar.isHidden = false

    }
    
    

    override func viewDidLoad() {
        super.viewDidLoad()
        self.title = "发布公告"
        self.navigationController?.navigationBar.isHidden = false
       
        
        // Do any additional setup after loading the view.
    }
//发布公告
    @IBAction func submit(_ sender: Any) {
        if !(titleTF.text?.isEmpty)! && !(contentView.text.isEmpty){
            let userinfo = UserDefaults.standard.object(forKey: USERINFO) as! [String:AnyObject];
            let token = "token" //userinfo["token"] as! String
            let id = userinfo["id"] 
            YMNetworkManager().postRequset(urlString: PUSH_ANNOUN_CEMENTS, params: ["token":token,"id":id,"title":titleTF.text ?? "","content":contentView.text ?? ""], success: { (responser) in
                if  responser["status"]?.int8Value != 0{
                    Toast(text: "发布成功", delay: 0, duration: 1.5).show()
                    self.navigationController?.popViewController(animated: true)
                }
            }, failture: { (error) in
                
            })
            
            
        }else{
            Toast(text: "标题和内容不能为空", delay: 0, duration: 1.5)
            return ;
        }
    
    }
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

 

}


extension YDOAAnnounceVC : UITextFieldDelegate ,UITextViewDelegate{
    
    func textFieldShouldReturn(_ textField: UITextField) -> Bool {
        textField.resignFirstResponder()
        return true
    }

    override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
        view.endEditing(true)
    }
    
    
    
    
}

